package com.wz.project.stock.record.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.stock.domain.BasStockMaintainRecord;
import com.wz.project.stock.record.service.IBasStockMaintainRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存维护记录Controller
 * 
 * @author wz
 * @date 2022-04-19
 */
@Controller
@RequestMapping("/stock/record")
public class BasStockMaintainRecordController extends BaseController
{
    private String prefix = "stock/record";

    @Autowired
    private IBasStockMaintainRecordService basStockMaintainRecordService;

    @RequiresPermissions("stock:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询库存维护记录列表
     */
//    @RequiresPermissions("stock:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasStockMaintainRecord basStockMaintainRecord)
    {
        startPage();
        List<BasStockMaintainRecord> list = basStockMaintainRecordService.selectBasStockMaintainRecordList(basStockMaintainRecord);
        return getDataTable(list);
    }

    /**
     * 导出库存维护记录列表
     */
    @RequiresPermissions("stock:record:export")
    @Log(title = "库存维护记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasStockMaintainRecord basStockMaintainRecord)
    {
        List<BasStockMaintainRecord> list = basStockMaintainRecordService.selectBasStockMaintainRecordList(basStockMaintainRecord);
        ExcelUtil<BasStockMaintainRecord> util = new ExcelUtil<BasStockMaintainRecord>(BasStockMaintainRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 新增库存维护记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存维护记录
     */
    @RequiresPermissions("stock:record:add")
    @Log(title = "库存维护记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasStockMaintainRecord basStockMaintainRecord)
    {
        return toAjax(basStockMaintainRecordService.insertBasStockMaintainRecord(basStockMaintainRecord));
    }

    /**
     * 修改库存维护记录
     */
    @GetMapping("/edit/{whGuid}")
    public String edit(@PathVariable("whGuid") String whGuid, ModelMap mmap)
    {
        BasStockMaintainRecord basStockMaintainRecord = basStockMaintainRecordService.selectBasStockMaintainRecordById(whGuid);
        mmap.put("basStockMaintainRecord", basStockMaintainRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存维护记录
     */
    @RequiresPermissions("stock:record:edit")
    @Log(title = "库存维护记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasStockMaintainRecord basStockMaintainRecord)
    {
        return toAjax(basStockMaintainRecordService.updateBasStockMaintainRecord(basStockMaintainRecord));
    }

    /**
     * 删除库存维护记录
     */
    @RequiresPermissions("stock:record:remove")
    @Log(title = "库存维护记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basStockMaintainRecordService.deleteBasStockMaintainRecordByIds(ids));
    }
}
